import string
import re
import sys
import os
import glob



def findAllFiles(sDirectory, listFileNames ):
    if not os.path.isdir(sDirectory):
        listFileNames.append(sDirectory)
        return

    for sFile in glob.glob(os.path.join(sDirectory, '*') ):
        if os.path.isdir(sFile):
            findAllFiles(sFile, listFileNames)
        else:
            listFileNames.append(sFile)

def findCommentFiles(sDirectory):
    reCodeFileName = re.compile('^[^\r\n]*\.txt$')
    listFileNames = []
    findAllFiles(sDirectory, listFileNames )
    listCodeFiles = []
    for sFile in listFileNames:
        #print sFile
        match = reCodeFileName.match(sFile)
        if match:
            listCodeFiles.append(sFile)

    return listCodeFiles


def parseCommentFile(sFileName):
    fFile = open(sFileName, 'r')
    iLineNumber = 0    
    reLabel = re.compile('^Label:[\s]+([0|1|2])')
    iLabel = -1

    while True:
        line = fFile.readline()
        if not line:
            break
        match = reLabel.match(line)
        if match:
            if int(match.group(1)) == 0:
                iLabel = 0
            elif int(match.group(1)) == 1:
                iLabel = 1
            elif int(match.group(1)) == 2:
                iLabel = 2
        iLineNumber = iLineNumber + 1
        if iLineNumber == 2:
            break
    
    fFile.close()   
    return iLabel


if __name__ == '__main__':
    if len(sys.argv) != 2:
        exit()

    listCommentFiles = findCommentFiles(sys.argv[1])
    iNot = 0 
    iDescription = 0
    iAssumption = 0

    for sName in listCommentFiles:
        iLabel = parseCommentFile(sName)
        if iLabel == 0:
            iNot = iNot + 1
        elif iLabel == 1:
            iDescription = iDescription + 1
        elif iLabel == 2:
            iAssumption = iAssumption + 1

    print 'Total:', len(listCommentFiles)
    print 'Label:', iNot + iDescription + iAssumption
    print 'Other:', iNot
    print 'Description:', iDescription
    print 'Assumption:', iAssumption
   

